// 获取时间数组的函数
export function getTimesFunc(dec) {
	// 十进制数据
	// let num = parseInt(hex, 16)
	// console.log("num", num)

	// 二进制数据
	let twoN = Number(dec).toString(2)
	// 补位后字符串
	let coveringPositionStr = coveringPositionFunc(twoN)
	// 二进制字符串变换顺序
	let reverseStr = coveringPositionStr.split("").reverse().join("")
	// 时间数组
	let times = extractOnTimeArrFunc(reverseStr)
	return times
}

// 提取整点数组函数
function extractOnTimeArrFunc(str) {
	let arr = []
	for (let i = 0; i < str.length; i++) {
		// 为1是有效数据，为0则是无效数据
		// 提取有效数据
		if (str[i] == 1) {
			arr.push(i)
		}
	}
	return arr
}

// 补位函数
function coveringPositionFunc(twoN) {
	// 原二进制长度
	let yLength = twoN.length
	// 分段数
	let subsectionN = Math.ceil(yLength / 4)
	// 输出长度
	let outLength = subsectionN * 4
	// 输出二进制字符串
	let outStr = twoN.padStart(outLength, "0")
	return outStr
}

// 根据整点时间数组获取16进制
export function getHexByTimes(arr) {
	let hex = ""
	let timeAll = [
		0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
	]
	let twoStr = ""
	for (let i = 0; i < timeAll.length; i++) {
		if (arr.indexOf(timeAll[i]) != -1) {
			twoStr += "1"
		} else {
			twoStr += "0"
		}
	}
	let reverseStr = twoStr.split("").reverse().join("")
	// console.log('二进制字符串', reverseStr)

	return parseInt(binaryStringToHexString(reverseStr), 16)
}

function binaryStringToHexString(binaryStr) {
	// 将二进制字符串转换为十进制数
	var decimalNumber = parseInt(binaryStr, 2)
	// 将十进制数转换为十六进制字符串
	var hexString = decimalNumber.toString(16)
	return hexString
}

export function mathTimeFunc(time) {
	let str = ""
	switch (time) {
		case 0:
			str = "00:00"
			break
		case 1:
			str = "01:00"
			break
		case 2:
			str = "02:00"
			break
		case 3:
			str = "03:00"
			break
		case 4:
			str = "04:00"
			break
		case 5:
			str = "05:00"
			break
		case 6:
			str = "06:00"
			break
		case 7:
			str = "07:00"
			break
		case 8:
			str = "08:00"
			break
		case 9:
			str = "09:00"
			break
		case 10:
			str = "10:00"
			break
		case 11:
			str = "11:00"
			break
		case 12:
			str = "12:00"
			break
		case 13:
			str = "13:00"
			break
		case 14:
			str = "14:00"
			break
		case 15:
			str = "15:00"
			break
		case 16:
			str = "16:00"
			break
		case 17:
			str = "17:00"
			break
		case 18:
			str = "18:00"
			break
		case 19:
			str = "19:00"
			break
		case 20:
			str = "20:00"
			break
		case 21:
			str = "21:00"
			break
		case 22:
			str = "22:00"
			break
		case 23:
			str = "23:00"
			break

		default:
			break
	}
	return str
}
